// TrainTypeEnum.java
package com.leo.train.common.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.math.BigDecimal;

@Getter
public enum TrainTypeEnum implements BaseEnum {
    G("G", "高铁", new BigDecimal("1.2")),
    D("D", "动车", new BigDecimal("1")),
    K("K", "快速", new BigDecimal("0.8"));

    private final String code;
    private final String description;
    private final BigDecimal price;

    TrainTypeEnum(String code, String description, BigDecimal price) {
        this.code = code;
        this.description = description;
        this.price = price;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    public static TrainTypeEnum fromCode(String code) {
        for (TrainTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }
}
